//*********基础功能重新封装**************//
var baseUrl = "/app_dev.php"
function apiGet( url , data , func){
    log("进入apiGet,正在获取数据")
    logJson(data)
    $.ajax({
        url : baseUrl + url,
        type : 'GET',
        data : data,
        headers: {
            // cookie: cookie()
        },
        success : function(data, status,requestCode,response, xhr) {

            // try{
            //     var res = JSON.parse(data)
            //     logJson(res);
            // }catch(e){
            //     showToast("数据异常");
            //     return;
            // }finally{
            // }
            apiDealWithResult(data,func)
        },
        error : function(e) {

        }
    });

}


function apiPost( url , data ,func){
    log("进入apiGet,正在获取数据")
    log(url)
    logJson(data)
    $.ajax({
        url : baseUrl + url,
        type : 'POST',
        data : data,
        headers: {
            // cookie: cookie()
        },
        success : function(data, status,requestCode,response, xhr) {

            apiDealWithResult(data,func)
        },
        error : function(e) {

        }
    });
}


function uploadOnePic (data ,func) {
    log("uploadOnePic")
    if (toOSS == 1 ) {
        uploadOnePicToOss(data,func)
    }else{
        var param = {Filedata:{path:data}}
        apiPost( "/MyWebPicUpload" , param ,func)
    }


}

function getCookie(response){
    response = JSON.parse(response);
    var headers = response.responseHeaders
    var cookies = [];
    for (var i in headers) {
        if (i == "Set-Cookie") {
            var arr = headers[i].split(";")
            cookies = arr[0];
        }
    }
    log("这是获取到的cookie");
    logJson(cookies);
    return cookies;
}

function cookie(){
    var cookie = getLocData("cookie");
    return cookie;
}




function apiDealWithResult(res,callback) {
    log("数据获取成功");
    log(res);
    callback(res)

}

